<template>
	<view>
		<u-navbar :title="title" :border-bottom='false'>
			<view slot='right' style="padding-right: 32rpx;font-size: 32rpx;color: #2D7AFE;" @click="submit">
				保存
			</view>
		</u-navbar>
		<view class="inputBox">
			<input type="text" v-model="name" :placeholder="placeholder" />
		</view>
	</view>
</template>

<script>
	import myRequest from '../../../api/index.js'
	export default {
		data() {
			return {
				placeholder: '请输入昵称',
				name: '',
				type:''
			}
		},
		onLoad(option) {
			this.name = option.textname
			this.type = option.type
			if(option.type ==0){
				this.title = '修改昵称'
			}
			if(option.type ==1){
				this.title = '修改姓名'
			}
		},
		methods: {
			async submit() {
				if(this.type==0){
					if (!this.name) {
						uni.showToast({
							title: '请输入昵称',
							icon: 'none'
						})
						return
					}
					let res = await myRequest.editUserInfo({
						nickname: this.name
					})
					if (res.status) {
						uni.showToast({
							title: '保存成功'
						})
						setTimeout(function(){
							uni.navigateBack({
								delta:1
							})
						},1000)
					}
				}
				if(this.type == 1) {
					if (!this.name) {
						uni.showToast({
							title: '请输入姓名',
							icon: 'none'
						})
						return
					}
					let data = await myRequest.editUserInfo({
						username: this.name
					})
					if (data.status) {
						uni.showToast({
							title: '保存成功'
						})
						setTimeout(function(){
							uni.navigateBack({
								delta:1
							})
						},1000)
					}
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.inputBox {
		margin: 32rpx auto 0;
		width: 694rpx;
		height: 100rpx;
		background: #FFFFFF;
		border-radius: 16rpx;

		input {
			width: 100%;
			height: 100%;
			text-indent: 20rpx;
			font-size: 28rpx;
		}
	}
</style>
